package net.wzw.controller;

import net.wzw.entity.FoodQueryEntity;
import net.wzw.entity.FoodSaveOrUpdateEntity;
import net.wzw.service.FoodService;
import net.wzw.vo.FoodVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import net.wzw.enums.BizCodes;
import net.wzw.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wzw
 * @date 2025/4/19
 * @Description
 */
@Api(tags = "美食微服务账号模块")
@Slf4j
@RestController
@RequestMapping("/api/food/v1/")
public class FoodController {

    @Autowired
    private FoodService foodService;

    @ApiOperation("查询美食信息")
    @GetMapping("/info/{food_id}")
    public Object getFoodInfo(
            @ApiParam(value= "美食id" ,required = true)
            @PathVariable("food_id") Long foodId){
        log.info("查询食谱信息:food_id:{}",foodId);

        FoodVO foodVO = foodService.getFoodInfo(foodId);

        return foodVO == null ? ApiResult.doResult(BizCodes.FOOD_INFO_NOT_EXITS) : ApiResult.doSuccess(foodVO);

    }

    @ApiOperation("分页查询我的美食列表")
    @PostMapping("/list")
    public ApiResult getFoodList(@RequestBody FoodQueryEntity foodQueryEntity){

        log.info("查询我的美食列表:{}",foodQueryEntity);
        Map<String,Object> foodInfoList  = foodService.getFoodList(foodQueryEntity);
        return  ApiResult.doSuccess(foodInfoList);

    }


    @ApiOperation("/新增或修改美食信息")
    @PostMapping("saveOrUpdate")
    public ApiResult SaveOrUpdate(@ApiParam("添加/修改美食信息") @RequestBody FoodSaveOrUpdateEntity foodSaveOrUpdateEntity){

        log.info("新增/修改美食信息:{}",foodSaveOrUpdateEntity);

        return  ApiResult.doSuccess();

    }


}
